import { EventNames } from "../Home/Data/EventNames";
import HttpAPI from "../HttpManager/HttpAPI";
import HttpManager from "../HttpManager/HttpManager";
import { LevelConfigInfo, LevelQuestionInfo } from "./LevelConfig";

export class StaticData {
    /** 昵称 */
    public static nickName = "";
    /** 头像 */
    public static headUrl = "";
    /** 手机号 */
    public static phoneNumber = "";
    /** 积分 */
    public static integral = 0;
    /** 是否新手引导完成1:已完成 0:未完成 */
    public static userGameGuide: number;
    /** token */
    public static getToken(): string {
        return Laya.LocalStorage.getItem("token")
    }
    /** token */
    public static setToken(v: string) {
        Laya.LocalStorage.setItem("token", v)
    }
    /** token */
    public static removeToken() {
        Laya.LocalStorage.removeItem("token")
    }

    /** code */
    public static getCode() {
        return Laya.LocalStorage.getItem("code")
    }
    /** code */
    public static setCode(v: string) {
        Laya.LocalStorage.setItem("code", v)
    }
    /** code */
    public static removeCode() {
        Laya.LocalStorage.removeItem("code")
    }
    /** 是否显示点击黑块 */
    public static showClickBlockCube = false;
    /** 跳关 */
    public static jumpLevel: number = undefined;
    /**  */
    public static readonly arrReasonStr = ["安全带低挂高用", "未填写日期", "过道木未铺满", "未正确接地"];
    // public static getErrInfo() {
    //     return StaticData.arrReasonStr
    // }  
    public static async getLevelConfig(level: number, callback: (a: any) => any) {
        const result = {
            "id": 27,
            "name": "关卡1",
            "tips": [
                "关卡1的提示"
            ],
            "barrierImgUrl": "https://h5.9shadow.com/xk/ImgTest1.png",
            "barrierItems": [
                {
                    "x": "0",
                    "y": "0",
                    "width": "50",
                    "height": "50",
                    "options": ["安全带低挂高用",
                        "朝天钉未处理",
                        "戴手套抡大锤",
                        "电焊机接地线"],
                    "barrierTipsAnswer": 0
                },
                {
                    "x": "374",
                    "y": "0",
                    "width": "50",
                    "height": "50",
                    "options": ["电缆井口未设置围栏，悬挂警示牌",
                        "电源盘试验标签涂改时间",
                        "吊带无标签，表面破损",
                        "绞磨转动部位无防护罩"],
                    "barrierTipsAnswer": 1
                },
                {
                    "x": "0",
                    "y": "268",
                    "width": "50",
                    "height": "50",
                    "options": ["绝缘斗臂车接地松动",
                        "坑洞口无围栏",
                        "灭火器露天放置",
                        "三措无审核批准时间"],
                    "barrierTipsAnswer": 2
                },
                {
                    "x": "374",
                    "y": "268",
                    "width": "50",
                    "height": "50",
                    "options": ["通风机外壳接地松动",
                        "接地体未插入地下",
                        "消防器材不合格",
                        "作业层未满铺"],
                    "barrierTipsAnswer": 3
                }
            ]
        }

        let levelConfigInfo: LevelConfigInfo = new LevelConfigInfo();
        levelConfigInfo.id = level;
        levelConfigInfo.tips = result.tips;
        levelConfigInfo.barrierImgUrl = result.barrierImgUrl;
        levelConfigInfo.arrLevelQuestion = [];
        for (let index = 0; index < result.barrierItems.length; index++) {
            const item = result.barrierItems[index];
            let info: LevelQuestionInfo = new LevelQuestionInfo(index, item);
            levelConfigInfo.arrLevelQuestion.push(info);
        }
        callback?.(levelConfigInfo)
    }

    // public static async getLevelConfig(level: number, callback: (a: any) => any) {
    //     let callbackObj: { success: boolean, result: { tips: string[], barrierImgUrl: string, barriers: any[] } };
    //     await HttpManager.get(HttpAPI.GET_LEVEL_CONFIG, { barrierId: level }, null).then(
    //         (data) => {
    //             callbackObj = data;
    //         }
    //     ).catch((e) => {
    //         console.log("Err", e);

    //     })
    //     console.log("successObj=>", callbackObj);
    //     if (callbackObj && callbackObj.success) {
    //         const result = callbackObj.result;
    //         // StaticData.arrReasonStr = result.tips;

    //         let levelConfigInfo: LevelConfigInfo = new LevelConfigInfo();
    //         levelConfigInfo.id = level;
    //         levelConfigInfo.tips = result.tips;
    //         levelConfigInfo.barrierImgUrl = result.barrierImgUrl;
    //         levelConfigInfo.arrLevelQuestion = [];
    //         for (let index = 0; index < result.barriers.length; index++) {
    //             const item = result.barriers[index];
    //             let info: LevelQuestionInfo = new LevelQuestionInfo(index, item);
    //             levelConfigInfo.arrLevelQuestion.push(info);
    //         }
    //         callback?.(levelConfigInfo)
    //     } else {
    //         Laya.stage.event(EventNames.POPUP_SHOW_COMMON_TIPS, "获取关卡" + level + "配置失败")
    //     }
    // }
    public static checkImageBase64(str: string): string {
        if (!str) return "";
        let pngPrefix = "data:image/png;base64,";
        let jpgPrefix = "data:image/jpeg;base64,";
        let strPrefix = str.slice(0, 10);
        if (strPrefix == "data:image") {
            return str;
        }

        let jpgPrefix2 = "/9j/";
        let str2 = str.slice(0, 4);
        if (str2 == jpgPrefix2) {
            return jpgPrefix + str;
        }
        let pngPrefix2 = "iVBORw0K";
        let str3 = str.slice(0, 8);
        if (str3 == pngPrefix2) {
            return pngPrefix + str;
        }
        return pngPrefix + str;
    }
}